<?php
/**
 * 核心文件
 * User: Administrator
 * Date: 2019/4/2
 * Time: 11:15
 */
namespace core;

class free
{
    public static $classMap = array();
    public $assgin;
    static public function run()
    {
       $route = new \core\lib\route();
       $ctrlClass = $route->ctrl;
       $action = $route->action;
       $ctrlFile = APP.'/ctrl/'.$ctrlClass.'Ctrl.php';
       $ctrlClass = '\\'.MODULE.'\ctrl\\'.$ctrlClass.'Ctrl';
       if(is_file($ctrlFile)){
           include $ctrlFile;
           $ctrl = new $ctrlClass();
           $ctrl->$action();
       } else {
           throw new \Exception('找不到控制器'.$ctrlClass);
       }
    }

    /**
     * 类的自动加载
     */
    static public function load($class)
    {
        if (isset($classMap[$class])) {
            return true;
        } else {
            $class = str_replace("\\","/",$class);
            $file = ROOT_PATH.'/'.$class.'.php';
            if (is_file($file)) {
                include $file;
                self::$classMap[$class] = $class;
            } else {
                return false;
            }
        }
    }

    /**
     * 视图分配变量
     */
    public function assign($name,$value)
    {
        $this->assign[$name] = $value;
    }

    /**
     * 视图显示
     */
    public function display($file)
    {
        $file = APP.'/view/'.$file;
        if (is_file($file)) {
            extract($this->assign);
            include $file;
        }
    }
}